<template>
	<view class="padding">
		<wd-cell-group class="wd-cell">
			<wd-input label-width="20%" readonly type="text" label="单位名称" v-model="warn.clientName" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="设备编号" v-model="warn.equipmentId" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="设备名称" v-model="warn.equipmentName" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="部件编号" v-model="warn.partModel" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="部件名称" v-model="warn.partName" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="报警地点" v-model="warn.warnAddr" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="报警时间" v-model="warn.warnTime" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="是否误报" v-model="warn.misinformationStatus"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="报警状态" v-model="warn.warnStateName"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="报警类型" v-model="warn.warnTypeName"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="处理状态" v-model="warn.dealStatus" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="报警说明" v-model="warn.warnExpl" placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="处理时间" v-model="warn.processingTime"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="消息通知" v-model="warn.teleNotificationStatus"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="故障上报" v-model="warn.faultReportStatus"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="故障上报备注" v-model="warn.faultReportExpl"
				placeholder="无数据" />
			<wd-cell title="故障上报图片" vertical>
				<view v-if="warn.faultReportUrl==null">
					无
				</view>
				<view v-else-if="getUrl(warn.faultReportUrl).type=='Array'"
					v-for="url in getUrl(warn.faultReportUrl).data"
					style="display: inline-block;">
					<image :src="this.$baseUrl + url" alt="图"
						class="photoPreview" />
				</view>
				<view v-else>
					<image :src="this.$baseUrl + getUrl(warn.faultReportUrl).data" alt="图"
						class="photoPreview" />
				</view>
			</wd-cell>
			<wd-input label-width="20%" readonly type="text" label="实地勘查" v-model="warn.fieldSurveyStatus"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="实地勘查备注" v-model="warn.fieldSurveyExpl"
				placeholder="无数据" />
			<wd-cell title="实地勘查图片" vertical>
				<view v-if="warn.fieldSurveyUrl==null">
					无
				</view>
				<view v-else-if="getUrl(warn.fieldSurveyUrl).type=='Array'"
					v-for="url in getUrl(warn.fieldSurveyUrl).data"
					style="display: inline-block;">
					<image :src="this.$baseUrl + url" alt="图"
						class="photoPreview" />
				</view>
				<view v-else>
					<image :src="this.$baseUrl + getUrl(warn.fieldSurveyUrl).data" alt="图"
						class="photoPreview" />
				</view>
			</wd-cell>
			<wd-input label-width="20%" readonly type="text" label="排除隐患" v-model="warn.eliminHidDangStatus"
				placeholder="无数据" />
			<wd-input label-width="20%" readonly type="text" label="排除隐患备注" v-model="warn.eliminHidDangExpl"
				placeholder="无数据" />
			<wd-cell title="排除隐患图片" vertical>
				<view v-if="warn.eliminHidDangUrl==null">
					无
				</view>
				<view v-else-if="getUrl(warn.eliminHidDangUrl).type=='Array'"
					v-for="url in getUrl(warn.eliminHidDangUrl).data"
					style="display: inline-block;">
					<image :src="this.$baseUrl + url" alt="图"
						class="photoPreview" />
				</view>
				<view v-else>
					<image :src="this.$baseUrl + getUrl(warn.eliminHidDangUrl).data" alt="图"
						class="photoPreview" />
				</view>
			</wd-cell>
			<wd-input label-width="20%" readonly type="text" label="创建时间" v-model="warn.createTime" placeholder="无数据" />
		</wd-cell-group>
		<DetailButton v-if="showDetailTypes.includes(warn.equipmentType)" @click="navigateToPage3(this.warn)" style="left: 90%;"/>
	</view>
</template>

<script>
	import DetailButton from '@/common/component/DetailButton.vue';
	export default {
		components: {
			DetailButton
		},
		onLoad(options) {
			this.warn = JSON.parse(options.data)
		},
		computed: {
			// 根据 warn.isDeal 的值显示“已处理”或“未处理”
			dealStatus() {
				return this.warn.isDeal === 1 ? "已处理" : "未处理";
			},
			misinformationStatus() {
				return this.warn.isMisinformation === '0' ? "真实" : "误报";
			},
			teleNotificationStatus() {
				return this.warn.teleNotification === '0' ? "未通知" : "已通知";
			},
			faultReportStatus() {
				return this.warn.faultReport === '0' ? "未上报" : "已上报";
			},
			fieldSurveyStatus() {
				return this.warn.fieldSurvey === '0' ? "未勘查" : "已勘查";
			},
			eliminHidDangStatus() {
				return this.warn.eliminHidDang === '0' ? "未排除" : "已排除";
			}
		},
		data() {
			return {
				warn: {},
				showDetailTypes: [52, 51, 42, 53, 44, 45, 43, 46],
			}
		},
		methods: {
			getUrl(url) {
				const urlResult = {
					type: "String",
					data: ""
				}
				if (url.includes(',')) {
					const urlList = url.split(',')
					urlResult.type = "Array"
					urlResult.data = urlList
					return urlResult
				}
				urlResult.data = url
				return urlResult
			},
			getState(isDeal) {
				if (isDeal == 1) {
					return "已处理"
				} else {
					return "未处理"
				}
			},
			navigateToPage3(data) {
				const routeMap = new Map([
					[52, { path: "/pages/warn/currentWarn" }],
					[51, { path: "/pages/warn/fireCockSysWarn" }],
					[42, { path: "/pages/warn/warnDq" }],
					[53, { path: "/pages/warn/warnJh" }],
					[44, { path: "/pages/warn/warnLs" }],
					[45, { path: "/pages/warn/warnQg" }],
					[43, { path: "/pages/warn/warnYg" }],
					[46, { path: "/pages/warn/warnDq" }],
				]);

				const routeConfig = routeMap.get(data.equipmentType);
				if (routeConfig) {
					// 构建带参数的URL
					const url = `${routeConfig.path}?id=${data.equipmentInputStoreId}&equipmentId=${data.equipmentId}&warnTime=${encodeURIComponent(data.warnTime)}`;

					uni.navigateTo({
						url: url
					});
				} else {
					console.warn(`未配置设备类型 ${data.equipmentType} 的路由`);
				}
			}
		}
	}
</script>

<style scoped>
	@import url("@/common/globleCSS/photoPreview.css");
	.wd-cell {
		border-radius: 10px;
	}

	:deep(.wd-cell-group__body) {
		border-radius: 10px;
	}

	:deep(.wd-input) {
		border-radius: 10px;
	}
</style>
